'use strict';
var baseUrl = 'http://catold.wicp.net:14119/rest/stu/';
var services = angular.module('CourseApp.services', ['ngResource']);
services.factory('StudentService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'students/:action:stuId', {
			action: '@action',
			stuId: '@stuId'
		}, {
			authenticate: {
				method: 'POST',
				params: {
					'action': 'authenticate'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
		});
	}
]);

services.factory('TeacherService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'teachers/:action/:teaId', {}, {
			authenticate: {
				method: 'POST',
				params: {
					'action': 'authenticate'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			get: {
				method: 'GET',
				params: {
					'action': 'gettea',
					'teaId': '@id'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('CourseInfoService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'courses/:couId:action/:couName', {
			couId: '@id',
			action: '@action',
			couName: '@couName',
		}, {
			getCourseByName: {
				method: 'GET',
				params: {
					'action': 'getCourseByName',
					'actionparam': '@couName'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('NoticeInfoService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'notices/:action/:couId', {
			couId: '@id'
		}, {
			getFirstNotice: {
				method: 'GET',
				params: {
					'action': 'getFirstNotice',
					'couId': '@id'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			getAll: {
				method: 'GET',
				params: {
					'action': 'getAll',
					'couId': '@id'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('StudentCourseService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'student_course/:action/:scId', {}, {
			addCourse: {
				method: 'POST',
				params: {
					'action': 'addcou',
					'couId': '@id'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			getInfo: {
				method: 'GET',
				params: {
					'action': 'get',
					'scId': '@id'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('LocateInfoService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'locates/:action', {}, {
			getInfo: {
				method: 'GET',
				params: {
					'action': 'get'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('QuestionInfoService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'questions/:queId:action/:couId/:pageNum', {
			'queId': '@id'
		}, {
			getQuestionByCouIdOrderByTime: {
				method: 'GET',
				params: {
					'action': 'getByTime',
					'couId': '@couId',
					'pageNum': '@pageNum'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			getQuestionByCouIdOrderByGood: {
				method: 'GET',
				params: {
					'action': 'getByGood',
					'couId': '@couId',
					'pageNum': '@pageNum'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			getAllOrderByTime: {
				method: 'GET',
				params: {
					'action': 'getAllByTime',
					'couId': '@couId',
					'pageNum': '@pageNum'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			getAllOrderByGood: {
				method: 'GET',
				params: {
					'action': 'getAllByGood',
					'couId': '@couId',
					'pageNum': '@pageNum'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			getQuestionBySelectedCourse: {
				method: 'GET',
				params: {
					'action': 'getQuestionBySelectedCourse',
					'couId': '@couId',
					'pageNum': '@pageNum'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('AnswerInfoService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'answers/:ansId:action/:queId:phrase', {
			ansId: '@id'
		}, {
			getAnswersByQueId: {
				method: 'GET',
				params: {
					'action': 'getAnswersByQueId',
					'queId': '@queId'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			phraseAnswer: {
				method: 'GET',
				params: {
					'ansId': '@ansId',
					'phrase': 'phrase'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			disPhraseAnswer: {
				method: 'GET',
				params: {
					'ansId': '@ansId',
					'phrase': 'disPhrase'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);